﻿ 

using System.Text.RegularExpressions;

namespace CarTrackr.Business.Validation 
{
    public class NumericRule : Rule
    {

        public override RuleType Type
        {
            get
            {
                return RuleType.Numeric;
            }
        }

        public override string Text
        {
            get
            {
                return PropertyName + " should be numeric.";
            }
        }

        public override bool Validate(string value)
        {
            return IsNumeric(value);
        }


        private  bool IsNumeric( string value)
        {

            if (value == null) return false;

            Regex regEx = new Regex(@"^\d+$");

            return regEx.Match(value).Success;

        }

    }
}
